#pragma once

#include <ConnectionBroker/server/Server.h>
#include <ConnectionBroker/clientconnection/TcpClientConnection.h>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/shared_ptr.hpp>

namespace ConnectionBroker
{
   typedef boost::shared_ptr<TcpServer> TcpServerPtr;
   class TcpClientConnection;
   class TcpServer : public ConnectionBroker::Server
   {
      protected: //Member variables
      boost::asio::io_service mIoService;
      boost::asio::ip::tcp::acceptor mAcceptor;
      boost::shared_ptr<boost::asio::ssl::context> mContext;

      public: //Constructor, destructor
      TcpServer(const ConnectionBroker::ServerSettings& settings, 
                boost::shared_ptr<boost::asio::ssl::context> pContext,
                serverCallback pAppCallback, 
                serverCallback pAppClientDisconnectCallback,
                serverCallback pAppClientConnectCallback);
      virtual ~TcpServer();

      public: //Interface
      void start();
      std::string getPassword() const;

      protected: //Utilities
      void handleAccept(TcpClientConnectionPtr pNextClient, const boost::system::error_code& error);
      void startAcceptingClients();
   };
}

